import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yp/config/index.dart';
import 'package:yp/router.dart';
import 'package:yp/widgets/button_widget.dart';
import 'package:yp/widgets/dialog.dart';
import 'package:yp/widgets/index.dart';
import 'package:yp/widgets/shop.dart';

/// 评价成功
class CommentSuccess extends StatefulWidget {
  const CommentSuccess({Key key}) : super(key: key);

  @override
  _CommentSuccessState createState() => _CommentSuccessState();
}

class _CommentSuccessState extends State<CommentSuccess>
    with SingleTickerProviderStateMixin {
  // AnimationController _controller;
  RefreshController _refreshController =
      RefreshController(initialRefresh: true);

  List<String> _infoList = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];

  @override
  void initState() {
    super.initState();
    Future.delayed(Duration(milliseconds: 100), () {
      _dialog();
    });
  }

  @override
  void dispose() {
    super.dispose();
    _refreshController.dispose();
  }

  void _onLoading() async {
    await Future.delayed(Duration(milliseconds: 1000), () {
      _infoList.addAll(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']);
    }).whenComplete(() {
      if (mounted) {
        _refreshController.loadComplete();
      }
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: YPNavigationBar('评价成功'),
      body: SmartRefresher(
        enablePullDown: false,
        enablePullUp: true,
        footer: ClassicFooter(),
        controller: _refreshController,
        onLoading: _onLoading,
        child: CustomScrollView(
          physics: BouncingScrollPhysics(),
          slivers: [
            SliverToBoxAdapter(
              child: Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.only(top: 26, bottom: 12),
                    child: Image.asset('assets/images/selectIcon1.png',
                        width: 36, height: 36),
                  ),
                  Text(
                    '评论成功！奖励正在向你飞奔而来~',
                    style: TextStyle(
                        color: EsColors.TitleSecondary,
                        fontSize: EsSizes.MD,
                        fontWeight: EsFontWeights.Normal),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(top: 20, bottom: 26),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        EsOutLineButton('返回首页',
                            fontSize: EsSizes.SM,
                            padding: EdgeInsets.symmetric(
                                vertical: 5, horizontal: 14), onTap: () {
                          print('返回首页');
                        }),
                        SizedBox(
                          width: 40,
                        ),
                        EsOutLineButton('查看奖品',
                            fontSize: EsSizes.SM,
                            padding: EdgeInsets.symmetric(
                                vertical: 5, horizontal: 14), onTap: () {
                          print('查看奖品');
                        })
                      ],
                    ),
                  ),
                  Row(
                    children: [
                      SizedBox(width: 30),
                      Expanded(
                          child: Container(
                              color: EsColors.ContentSecondary, height: 1)),
                      SizedBox(width: 10),
                      Text(
                        '以下订单还未评论',
                        style: TextStyle(
                            color: EsColors.ContentSecondary,
                            fontSize: EsSizes.MD,
                            fontWeight: EsFontWeights.Normal),
                      ),
                      SizedBox(width: 10),
                      Expanded(
                          child: Container(
                              color: EsColors.ContentSecondary, height: 1)),
                      SizedBox(width: 30),
                    ],
                  ),
                  SizedBox(height: 15),
                ],
              ),
            ),
            SliverList(
              delegate: SliverChildBuilderDelegate((ctx, index) {
                return _orderItem();
              }, childCount: _infoList.length),
            ),
          ],
        ),
      ),
    );
  }

  /// 订单item
  Widget _orderItem() {
    return GestureDetector(
      onTap: () {
        /// 查看商品详情
        Get.toNamed(RouteConfig.orderDetail);
      },
      child: Container(
        color: EsColors.White,
        child: Column(
          children: [
            ShopName(
              '昆山旧城店',
              orderState: '待评价',
            ),
            YpLine(),
            GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                print('查看购买商品');
              },
              child: Container(
                margin:
                    const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
                child: Row(
                  children: [
                    Expanded(
                        child: Wrap(
                      spacing: 6,
                      children: List.generate(
                          4,
                          (index) => CachedImage(
                                width: (MediaQuery.of(context).size.width / 7),
                                height: MediaQuery.of(context).size.width / 7,
                                path:
                                    'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fbdn.135editor.com%2Ffiles%2Fusers%2F73%2F738683%2F201810%2FBfIVpTUH_SnJY.gif&refer=http%3A%2F%2Fbdn.135editor.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633256466&t=956aa5d483eaf297e5a68e5e97321390',
                                border: Border.all(
                                    color: EsColors.BackGroundSecondary,
                                    width: 1),
                              )),
                    )),
                    // SizedBox(width: 8),
                    Text(
                      '共' + '4' + '件',
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                          color: EsColors.ContentSecondary,
                          fontSize: EsSizes.SM,
                          fontWeight: EsFontWeights.Normal),
                    )
                  ],
                ),
              ),
            ),
            YpLine(),
            SizedBox(height: 12),
            Row(
              children: [
                SizedBox(width: 12),
                RichText(
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  text: TextSpan(
                      text: '实付：￥',
                      style: TextStyle(
                          fontSize: EsSizes.XS,
                          color: EsColors.TitleSecondary,
                          fontWeight: EsFontWeights.Normal),
                      children: <TextSpan>[
                        TextSpan(
                            text: '298.67',
                            style: TextStyle(
                                fontSize: EsSizes.LG,
                                color: EsColors.TitleSecondary,
                                fontWeight: EsFontWeights.Medium)),
                      ]),
                ),
                Expanded(child: SizedBox()),
                Padding(
                  padding: const EdgeInsets.only(right: 12),
                  child: EsOutLineButton(
                    '评价有礼',
                    padding: EdgeInsets.symmetric(vertical: 5, horizontal: 16),
                    onTap: () {
                      print('评价有礼');
                    },
                  ),
                )
              ],
            ),
            SizedBox(height: 20),
            YpLine(height: 20, thickness: 20),
          ],
        ),
      ),
    );
  }

  /// 奖励还在路上
  void _dialog() {
    YpShowDialog.dialog(
      context,
      Container(
        width: double.infinity,
        height: 80,
        margin: EdgeInsets.symmetric(horizontal: 20),
        alignment: Alignment.center,
        decoration: EsDecoration.BoxShadowWithRadius,
        child: RichText(
          textAlign: TextAlign.center,
          text: TextSpan(
              text: '奖品还在路上，最终发放奖品到\n',
              style: TextStyle(
                  fontSize: EsSizes.SM,
                  color: EsColors.Title,
                  fontWeight: EsFontWeights.Normal),
              children: <TextSpan>[
                TextSpan(
                    text: '我的奖励',
                    style: TextStyle(
                        fontSize: EsSizes.SM,
                        color: EsColors.Primary,
                        fontWeight: EsFontWeights.Normal),
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        print('我的奖励');
                        Navigator.of(context).pop();
                      }),
                TextSpan(
                    text: '中查看！',
                    style: TextStyle(
                        fontSize: EsSizes.SM,
                        color: EsColors.Title,
                        fontWeight: EsFontWeights.Normal)),
              ]),
        ),
      ),
    
    );
  
  }


}
